home *** CD-ROM | disk | FTP | other *** search
/ Halting the Hacker - A P…uide to Computer Security / Halting the Hacker - A Practical Guide to Computer Security.iso / rfc / rfc1523.txt < prev    next >
Text File  |  1997-04-01  |  33KB  |  843 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                      N. Borenstein
  8. Request for Comments: 1523                                      Bellcore
  9. Category: Informational                                   September 1993
  10.  
  11.  
  12.                   The text/enriched MIME Content-type
  13.  
  14. Status of this Memo
  15.  
  16.    This memo provides information for the Internet community.  It does
  17.    not specify an Internet standard.  Distribution of this memo is
  18.    unlimited.
  19.  
  20. Abstract
  21.  
  22.    MIME [RFC-1341, RFC-1521] defines a format and general framework for
  23.    the representation of a wide variety of data types in Internet mail.
  24.    This document defines one particular type of MIME data, the
  25.    text/enriched type, a refinement of the "text/richtext" type defined
  26.    in RFC 1341.  The text/enriched MIME type is intended to facilitate
  27.    the wider interoperation of simple enriched text across a wide
  28.    variety of hardware and software platforms.
  29.  
  30. The Text/enriched MIME type
  31.  
  32.    In order to promote the wider interoperability of simple formatted
  33.    text, this document defines an extremely simple subtype of the MIME
  34.    content-type "text", the "text/enriched" subtype.  This subtype was
  35.    designed to meet the following criteria:
  36.  
  37.          1.  The syntax must be extremely simple to parse, so that even
  38.          teletype-oriented mail systems can easily strip away the
  39.          formatting information and leave only the readable text.
  40.  
  41.          2.  The syntax must be extensible to allow for new formatting
  42.          commands that are deemed essential for some application.
  43.  
  44.          3.  If the character set in use is ASCII or an 8- bit ASCII
  45.          superset, then the raw form of the data must be readable enough
  46.          to be largely unobjectionable in the event that it is displayed
  47.          on the screen of the user of a non-MIME-conformant mail reader.
  48.  
  49.          4.  The capabilities must be extremely limited, to ensure that
  50.          it can represent no more than is likely to be representable by
  51.          the user's primary word processor.  While this limits what can
  52.          be sent, it increases the likelihood that what is sent can be
  53.          properly displayed.
  54.  
  55.  
  56.  
  57.  
  58. Borenstein                                                      [Page 1]
  59.  
  60. RFC 1523           A text/enriched MIME Content-type      September 1993
  61.  
  62.  
  63.    This document defines a new MIME content-type, "text/enriched".  The
  64.    content-type line for this type may have one optional parameter, the
  65.    "charset" parameter, with the same values permitted for the
  66.    "text/plain" MIME content-type.
  67.  
  68.    The syntax of "text/enriched" is very simple.  It represents text in
  69.    a single character set -- US-ASCII by default, although a different
  70.    character set can be specified by the use of the "charset" parameter.
  71.    (The semantics of text/enriched in non-ASCII character sets are
  72.    discussed later in this document.)  All characters represent
  73.    themselves, with the exception of the "<" character (ASCII 60), which
  74.    is used to mark the beginning of a formatting command.  Formatting
  75.    instructions consist of formatting commands surrounded by angle
  76.    brackets ("<>", ASCII 60 and 62).  Each formatting command may be no
  77.    more than 60 characters in length, all in US-ASCII, restricted to the
  78.    alphanumeric and hyphen ("-") characters.  Formatting commands may be
  79.    preceded by a solidus ("/", ASCII 47), making them negations, and
  80.    such negations must always exist to balance the initial opening
  81.    commands.  Thus, if the formatting command "<bold>" appears at some
  82.    point, there must later be a "</bold>" to balance it.  (NOTE: The 60
  83.    character limit on formatting commands does NOT include the "<", ">",
  84.    or "/" characters that might be attached to such commands.)
  85.  
  86.    Formatting commands are always case-insensitive.  That is, "bold" and
  87.    "BoLd" are equivalent in effect, if not in good taste.
  88.  
  89.    Beyond tokens delimited by "<" and ">", there are two other special
  90.    processing rules.  First, a literal less-than sign ("<") can be
  91.    represented by a sequence of two such characters, "<<".  Second, line
  92.    breaks (CRLF pairs in standard network representation) are handled
  93.    specially.  In particular, isolated CRLF pairs are translated into a
  94.    single SPACE character.  Sequences of N consecutive CRLF pairs,
  95.    however, are translated into N-1 actual line breaks.  This permits
  96.    long lines of data to be represented in a natural- looking manner
  97.    despite the frequency of line-wrapping in Internet mailers.  When
  98.    preparing the data for mail transport, isolated line breaks should be
  99.    inserted wherever necessary to keep each line shorter than 80
  100.    characters.  When preparing such data for presentation to the user,
  101.    isolated line breaks should be replaced by a single SPACE character,
  102.    and N consecutive CRLF pairs should be presented to the user as N-1
  103.    line breaks.
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. Borenstein                                                      [Page 2]
  115.  
  116. RFC 1523           A text/enriched MIME Content-type      September 1993
  117.  
  118.  
  119.    Thus text/enriched data that looks like this:
  120.  
  121.                     This is
  122.                     a single
  123.                     line
  124.  
  125.                     This is the
  126.                     next line.
  127.  
  128.                     This is the
  129.                     next paragraph.
  130.  
  131.    should be displayed by a text/enriched interpreter as follows:
  132.  
  133.                     This is a single line
  134.                     This is the next line.
  135.  
  136.                     This is the next paragraph.
  137.  
  138.    The formatting commands, not all of which will be implemented by all
  139.    implementations, are described in the following sections.
  140.  
  141.    Formatting Commands
  142.  
  143.    The text/enriched formatting commands all begin with <commandname>
  144.    and end with </commandname>, affecting the formatting of the text
  145.    between those two tokens.  The commands are described here, grouped
  146.    according to type.
  147.  
  148.    Font-Alteration Commands
  149.  
  150.    The following formatting commands are intended to alter the font in
  151.    which text is displayed, but not to alter the indentation or
  152.    justification state of the text:
  153.  
  154.          Bold -- causes the affected text to be in a bold font.  Nested
  155.               bold commands have the same effect as a single bold
  156.               command.
  157.  
  158.          Italic -- causes the affected text to be in an italic font.
  159.               Nested italic commands have the same effect as a single
  160.               italic command.
  161.  
  162.          Fixed -- causes the affected text to be in a fixed width font.
  163.               Nested fixed commands have the same effect as a single
  164.               fixed command.
  165.  
  166.  
  167.  
  168.  
  169.  
  170. Borenstein                                                      [Page 3]
  171.  
  172. RFC 1523           A text/enriched MIME Content-type      September 1993
  173.  
  174.  
  175.          Smaller -- causes the affected text to be in a smaller font.
  176.               It is recommended that the font size be changed by two
  177.               points, but other amounts may be more appropriate in some
  178.               environments.  Nested smaller commands produce ever-
  179.               smaller fonts, to the limits of the implementation's
  180.               capacity to reasonably display them, after which further
  181.               smaller commands have no incremental effect.
  182.  
  183.          Bigger -- causes the affected text to be in a bigger font.  It
  184.               is recommended that the font size be changed by two
  185.               points, but other amounts may be more appropriate in some
  186.               environments.  Nested bigger commands produce ever-bigger
  187.               fonts, to the limits of the implementation's capacity to
  188.               reasonably display them, after which further bigger
  189.               commands have no incremental effect.
  190.  
  191.          Underline -- causes the affected text to be underlined.  Nested
  192.               underline commands have the same effect as a single
  193.               underline command.
  194.  
  195.    While the "bigger" and "smaller" operators are effectively inverses,
  196.    it is not recommended, for example, that "<smaller>" be used to end
  197.    the effect of "<bigger>".  This is properly done with "</bigger>".
  198.  
  199.    Justification Commands
  200.  
  201.    Initially, text/enriched text is intended to be displayed fully-
  202.    justified with appropriate fill, kerning, and letter-tracking as
  203.    suits the capabilities of the receiving user agent software.  Actual
  204.    line width is left to the discretion of the receiver, which is
  205.    expected to fold lines intelligently (preferring soft line breaks) to
  206.    the best of its ability.
  207.  
  208.    The following commands alter that state.  Each of these commands
  209.    force a line break before and after the formatting command if there
  210.    is not otherwise a line break.  For example, if one of these commands
  211.    occurs anywhere other than the beginning of a line of text as
  212.    presented, a new line is begun.
  213.  
  214.       Center -- causes the affected text to be centered.
  215.  
  216.       FlushLeft -- causes the affected text to be left-justified with a
  217.            ragged right margin.
  218.  
  219.       FlushRight -- causes the affected text to be right-justified with
  220.            a ragged left margin.
  221.  
  222.  
  223.  
  224.  
  225.  
  226. Borenstein                                                      [Page 4]
  227.  
  228. RFC 1523           A text/enriched MIME Content-type      September 1993
  229.  
  230.  
  231.    The center, flushleft, and flushright commands are mutually
  232.    exclusive, and, when nested, the inner command takes precedence.
  233.  
  234.    Note that for some non-ASCII character sets, full justification may
  235.    be inappropriate. In these cases, a user agent may choose not to
  236.    justify such data.
  237.  
  238.    Indentation Commands
  239.  
  240.    Initially, text/enriched text is displayed using the maximum
  241.    available margins.  Two formatting commands may be used to affect the
  242.    margins.
  243.  
  244.          Indent -- causes the running left margin to be moved to the
  245.               right.  The recommended indentation change is the width of
  246.               four characters, but this may differ among
  247.               implementations.
  248.  
  249.          IndentRight -- causes the running right margin to be moved to
  250.               the left.  The recommended indentation change is the width
  251.               of four characters, but this may differ among
  252.               implementations.
  253.  
  254.    A line break is NOT forced by a change of the margin, to permit the
  255.    description of "hanging" text.  Thus for example the following text:
  256.  
  257.    Now <indent> is the time for all good horses to come to the aid of
  258.    their stable, assuming that </indent> any stable is really stable.
  259.  
  260.    would be displayed in a 40-character-wide window as follows:
  261.  
  262.    Now is the time for all good horses to
  263.        come to the aid of their stable,
  264.        assuming that any stable is
  265.    really stable.
  266.  
  267.    Miscellaneous Commands
  268.  
  269.          Excerpt -- causes the affected text to be interpreted as a
  270.               textual excerpt from another source, probably a message
  271.               being responded to.  Typically this will be displayed
  272.               using indentation and an alternate font, or by indenting
  273.               lines and preceding them with "> ", but such decisions are
  274.               up to the implementation.  (Note that this is the only
  275.               truly declarative markup construct in text/enriched, and
  276.               as such doesn't fit very well with the other facilities,
  277.               but it describes a type of markup that is very commonly
  278.               used in email and has no procedural analogue.)  Note that
  279.  
  280.  
  281.  
  282. Borenstein                                                      [Page 5]
  283.  
  284. RFC 1523           A text/enriched MIME Content-type      September 1993
  285.  
  286.  
  287.               as with the justification commands, the excerpt command
  288.               implicitly begins and ends with a line break if one is not
  289.               already there.
  290.  
  291.          Verbatim -- causes the affected text to be displayed without
  292.               filling, justification, any interpretation of embedded
  293.               formatting commands, or the usual special rules for CRLF
  294.               handling.  Note, however, that the end token </verbatim>
  295.               must still be recognized.
  296.  
  297.          Nofill -- causes the affected text to be displayed without
  298.               filling or justification, and hence without any special
  299.               handling of CRLFs, but with all remaining text/enriched
  300.               features continuing to apply.
  301.  
  302.          Param -- Marks the affected text as command parameters, to be
  303.               interpreted or ignored by the text/enriched interpreter,
  304.               but NOT to be shown to the reader.
  305.  
  306.    Note that while the absence of a quoting mechanism makes it slightly
  307.    challenging to include the literal string "<verbatim>" inside of a
  308.    verbatim environment, it can be done by breaking up the verbatim
  309.    segment into two verbatim segments as follows:
  310.  
  311.           <verbatim>
  312.           ...slightly challenging to include the literal string
  313.           "</</verbatim><verbatim>verbatim>" inside of a verbatim
  314.           environment...
  315.           </verbatim>
  316.  
  317.    Note that the above example demonstrates that it is not desirable for
  318.    an implementation to break lines between tokens.  In particular,
  319.    there should not be a line break inserted between the "</verbatim>"
  320.    and the "<verbatim>" that follows it.
  321.  
  322.    Balancing and Nesting of Formatting Commands
  323.  
  324.    Pairs of formatting commands must be properly balanced and nested.
  325.    Thus, a proper way to describe text in bold italics is:
  326.  
  327.            <bold><italic>the-text</italic></bold>
  328.  
  329.         or, alternately,
  330.  
  331.            <italic><bold>the-text</bold></italic>
  332.  
  333.         but, in particular, the following is illegal
  334.         text/enriched:
  335.  
  336.  
  337.  
  338. Borenstein                                                      [Page 6]
  339.  
  340. RFC 1523           A text/enriched MIME Content-type      September 1993
  341.  
  342.  
  343.            <bold><italic>the-text</bold></italic>
  344.  
  345.    The nesting requirement for formatting commands imposes a slightly
  346.    higher burden upon the composers of text/enriched bodies, but
  347.    potentially simplifies text/enriched displayers by allowing them to
  348.    be stack-based.  The main goal of text/enriched is to be simple
  349.    enough to make multifont, formatted email widely readable, so that
  350.    those with the capability of sending it will be able to do so with
  351.    confidence.  Thus slightly increased complexity in the composing
  352.    software was deemed a reasonable tradeoff for simplified reading
  353.    software.  Nonetheless, implementors of text/enriched readers are
  354.    encouraged to follow the general Internet guidelines of being
  355.    conservative in what you send and liberal in what you accept.  Those
  356.    implementations that can do so are encouraged to deal reasonably with
  357.    improperly nested text/enriched data.
  358.  
  359.    Unrecognized formatting commands
  360.  
  361.    Implementations must regard any unrecognized formatting command as
  362.    "no-op" commands, that is, as commands having no effect, thus
  363.    facilitating future extensions to "text/enriched".  Private
  364.    extensions may be defined using formatting commands that begin with
  365.    "X-", by analogy to Internet mail header field names.
  366.  
  367.    In order to formally define extended commands, a new Internet
  368.    document should be published.
  369.  
  370.    "White Space" in text/enriched Data
  371.  
  372.    No special behavior is required for the SPACE or TAB (HT) character.
  373.    It is recommended, however, that, at least when fixed-width fonts are
  374.    in use, the common semantics of the TAB (HT) character should be
  375.    observed, namely that it moves to the next column position that is a
  376.    multiple of 8.  (In other words, if a TAB (HT) occurs in column n,
  377.    where the leftmost column is column 0, then that TAB (HT) should be
  378.    replaced by 8-(n mod 8) SPACE characters.)  It should also be noted
  379.    that some mail gateways are notorious for losing (or, less commonly,
  380.    adding) white space at the end of lines, so reliance on SPACE or TAB
  381.    characters at the end of a line is not recommended.
  382.  
  383. Initial State of a text/enriched interpreter
  384.  
  385.    Text/enriched is assumed to begin with filled, fully justified text
  386.    in a variable-width font in a normal typeface and a size that is
  387.    average for the current display and user.  The left and right margins
  388.    are assumed to be maximal, that is, at the leftmost and rightmost
  389.    acceptable positions.
  390.  
  391.  
  392.  
  393.  
  394. Borenstein                                                      [Page 7]
  395.  
  396. RFC 1523           A text/enriched MIME Content-type      September 1993
  397.  
  398.  
  399.    Non-ASCII character sets
  400.  
  401.    If the character set specified by the charset parameter on the
  402.    Content-type line is anything other than "US-ASCII", this means that
  403.    the text being described by text/enriched formatting commands is in a
  404.    non-ASCII character set.  However, the commands themselves are still
  405.    the same ASCII commands that are defined in this document.  This
  406.    creates an ambiguity only with reference to the "<" character, the
  407.    octet with numeric value 60.  In single byte character sets, such as
  408.    the ISO-8859 family, this is not a problem; the octet 60 can be
  409.    quoted by including it twice, just as for ASCII.  The problem is more
  410.    complicated, however, in the case of multi-byte character sets, where
  411.    the octet 60 might appear at any point in the byte sequence for any
  412.    of several characters.
  413.  
  414.    In practice, however, most multibyte character sets address this
  415.    problem internally. For example, the ISO-2022 family of character
  416.    sets can switch back into ASCII at any moment.  Therefore it is
  417.    specified that, before text/enriched formatting commands, the
  418.    prevailing character set should be "switched back" into ASCII, and
  419.    that only those characters which would be interpreted as "<" in plain
  420.    text should be interpreted as token delimiters in text/enriched.
  421.  
  422.    The question of what to do for hypothetical future character sets
  423.    that do NOT subsume ASCII is not addressed in this memo.
  424.  
  425.    Minimal text/enriched conformance
  426.  
  427.    A minimal text/enriched implementation is one that simply recognizes
  428.    the beginning and ending of "verbatim" environments and, outside of
  429.    them, converts "<<" to "<", removes everything between a <param>
  430.    command and the next balancing </param> command, removes all other
  431.    formatting commands (all text enclosed in angle brackets), converts
  432.    any series of n CRLFs to n-1 CRLFs, and converts any lone CRLF pairs
  433.    to SPACE.
  434.  
  435.    Notes for Implementors
  436.  
  437.    It is recognized that implementors of future mail systems will want
  438.    rich text functionality far beyond that currently defined for
  439.    text/enriched.  The intent of text/enriched is to provide a common
  440.    format for expressing that functionality in a form in which much of
  441.    it, at least, will be understood by interoperating software.  Thus,
  442.    in particular, software with a richer notion of formatted text than
  443.    text/enriched can still use text/enriched as its basic
  444.    representation, but can extend it with new formatting commands and by
  445.    hiding information specific to that software system in text/enriched
  446.    <param> constructs. As such systems evolve, it is expected that the
  447.  
  448.  
  449.  
  450. Borenstein                                                      [Page 8]
  451.  
  452. RFC 1523           A text/enriched MIME Content-type      September 1993
  453.  
  454.  
  455.    definition of text/enriched will be further refined by future
  456.    published specifications, but text/enriched as defined here provides
  457.    a platform on which evolutionary refinements can be based.
  458.  
  459.    An expected common way that sophisticated mail programs will generate
  460.    text/enriched data is as part of a multipart/alternative construct.
  461.    For example, a mail agent that can generate enriched mail in ODA
  462.    format can generate that mail in a more widely interoperable form by
  463.    generating both text/enriched and ODA versions of the same data,
  464.    e.g.:
  465.  
  466.          Content-type: multipart/alternative; boundary=foo
  467.  
  468.          --foo
  469.          Content-type: text/enriched
  470.  
  471.          [text/enriched version of data]
  472.          --foo
  473.          Content-type: application/oda
  474.  
  475.          [ODA version of data]
  476.          --foo--
  477.  
  478.    If such a message is read using a MIME-conformant mail reader that
  479.    understands ODA, the ODA version will be displayed; otherwise, the
  480.    text/enriched version will be shown.
  481.  
  482.    In some environments, it might be impossible to combine certain
  483.    text/enriched formatting commands, whereas in others they might be
  484.    combined easily.  For example, the combination of <bold> and <italic>
  485.    might produce bold italics on systems that support such fonts, but
  486.    there exist systems that can make text bold or italicized, but not
  487.    both.  In such cases, the most recently issued (innermost) recognized
  488.    formatting command should be preferred.
  489.  
  490.    One of the major goals in the design of text/enriched was to make it
  491.    so simple that even text-only mailers will implement enriched-to-
  492.    plain-text translators, thus increasing the likelihood that enriched
  493.    text will become "safe" to use very widely.  To demonstrate this
  494.    simplicity, an extremely simple C program that converts text/enriched
  495.    input into plain text output is included in Appendix A.
  496.  
  497.    Extensions to text/enriched
  498.  
  499.    It is expected that various mail system authors will desire
  500.    extensions to text/enriched.  The simple syntax of text/enriched, and
  501.    the specification that unrecognized formatting commands should simply
  502.    be ignored, are intend to promote such extensions.
  503.  
  504.  
  505.  
  506. Borenstein                                                      [Page 9]
  507.  
  508. RFC 1523           A text/enriched MIME Content-type      September 1993
  509.  
  510.  
  511.    Beyond simply defining new formatting commands, however, it may
  512.    sometimes be necessary to define formatting commands that can take
  513.    arguments.  This is the intended use of the <param> construct.  In
  514.    particular, software that wished to extend text/enriched to include
  515.    colored text might define an "x-color" environment which always began
  516.    with a color name parameter, to indicate the desired color for the
  517.    affected text.
  518.  
  519.    An Example
  520.  
  521.    Putting all this together, the following "text/enriched" body
  522.    fragment:
  523.  
  524.          From: Nathaniel Borenstein <nsb@bellcore.com>
  525.          To: Ned Freed <ned@innosoft.com>
  526.          Content-type: text/enriched
  527.  
  528.          <bold>Now</bold> is the time for
  529.          <italic>all</italic> good men
  530.          <smaller>(and <<women>)</smaller> to
  531.          <ignoreme>come</ignoreme>
  532.  
  533.          to the aid of their
  534.  
  535.          <x-color><param>red</param>beloved</x-color>country.
  536.          <verbatim>
  537.          By the way, I think that <smaller>
  538.          should
  539.          REALLY be called
  540.          <tinier>
  541.          and that I am always right.
  542.          -- the end
  543.          </verbatim>
  544.  
  545.    represents the following formatted text (which will, no doubt, look
  546.    somewhat cryptic in the text-only version of this document):
  547.  
  548.          Now is the time for all good men (and <women>)  to
  549.          come
  550.          to the aid of their
  551.  
  552.          beloved country.
  553.          By the way, I think that <smaller>
  554.          should
  555.          REALLY be called
  556.          <tinier>
  557.          and that I am always right.
  558.          -- the end
  559.  
  560.  
  561.  
  562. Borenstein                                                     [Page 10]
  563.  
  564. RFC 1523           A text/enriched MIME Content-type      September 1993
  565.  
  566.  
  567.    where the word "beloved" would be in red on a color display if the
  568.    receiving software implemented the "x-color" extension.
  569.  
  570. Security Considerations
  571.  
  572.    Security issues are not discussed in this memo, as the mechanism
  573.    raises no security issues.
  574.  
  575. Author's Address
  576.  
  577.    For more information, the author of this document may be contacted
  578.    via Internet mail:
  579.  
  580.    Nathaniel S. Borenstein
  581.    MRE 2D-296, Bellcore
  582.    445 South St.
  583.    Morristown, NJ 07962-1910
  584.  
  585.    Phone: +1 201 829 4270
  586.    Fax:  +1 201 829 5963
  587.    EMail: nsb@bellcore.com
  588.  
  589. Acknowledgements
  590.  
  591.    This document reflects the input of many contributors, readers, and
  592.    implementors of the original MIME specification, RFC 1341.  This memo
  593.    also reflects particular contributions and comments from Terry
  594.    Crowley and Rhys Weatherley.
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618. Borenstein                                                     [Page 11]
  619.  
  620. RFC 1523           A text/enriched MIME Content-type      September 1993
  621.  
  622.  
  623. Appendix A -- A Simple enriched-to-plain Translator in C
  624.  
  625.    One of the major goals in the design of the text/enriched subtype of
  626.    the text Content-Type is to make formatted text so simple that even
  627.    text-only mailers will implement enriched-to-plain-text translators,
  628.    thus increasing the likelihood that multifont text will become "safe"
  629.    to use very widely.  To demonstrate this simplicity, what follows is
  630.    a simple C program that converts text/enriched input into plain text
  631.    output.  Note that the local newline convention (the single character
  632.    represented by "\n") is assumed by this program, but that special
  633.    CRLF handling might be necessary on some systems.
  634.  
  635.  
  636.                  #include <stdio.h>
  637.                  #include <ctype.h>
  638.  
  639.                  main() {
  640.                      int c, i, paramct=0, newlinect=0, verbatim=0,
  641.                  nofill=0;
  642.                      char token[62], *p;
  643.  
  644.                      while ((c=getc(stdin)) != EOF) {
  645.                          if (c == '<') {
  646.                              if (verbatim != 0) {
  647.                                  for (i=0, p=token; (*p++ = getc(stdin))
  648.                  != EOF
  649.                                      && !lc2strncmp(token, "/verbatim>",
  650.                  i+1) && i<9; i++) {}
  651.                                  if (i==9) {
  652.                                      verbatim = 0;
  653.                                  } else {
  654.                                      *p = '\0';
  655.                                      putc('<', stdout);
  656.                                      fputs(token, stdout);
  657.                                  }
  658.                                  continue;
  659.                              } else {
  660.                                  newlinect=0;
  661.                                  c = getc(stdin);
  662.                                  if (c == '<') {
  663.                                      if (paramct <= 0) putc(c, stdout);
  664.                                  } else {
  665.                                      ungetc(c, stdin);
  666.                                      for (i=0, p=token; (c=getc(stdin))
  667.                  != EOF && c != '>'; i++) {
  668.                                          if (i < sizeof(token)-1) *p++ =
  669.                  isupper(c) ? tolower(c) : c;
  670.                                      }
  671.  
  672.  
  673.  
  674. Borenstein                                                     [Page 12]
  675.  
  676. RFC 1523           A text/enriched MIME Content-type      September 1993
  677.  
  678.  
  679.                                      *p = '\0';
  680.                                      if (c == EOF) break;
  681.                                      if (strcmp(token, "param") == 0)
  682.                                          paramct++;
  683.                                      else if (strcmp(token, "verbatim")
  684.                  == 0)
  685.                                          verbatim = 1;
  686.                                      else if (strcmp(token, "nofill") ==
  687.                  0)
  688.                                          nofill++;
  689.                                      else if (strcmp(token, "/param") ==
  690.                  0)
  691.                                          paramct--;
  692.                                      else if (strcmp(token, "/nofill")
  693.                  == 0)
  694.  
  695.                                          nofill--;
  696.                                  }
  697.                              }
  698.                       } else {
  699.                          if (paramct > 0)
  700.                            ; /* ignore params */
  701.                             else if (c == '\n' && verbatim == 0 &&
  702.                  nofill <= 0)
  703.                                 if (++newlinect > 1) {
  704.                                     putc(c, stdout);
  705.                                 } else {
  706.                                     putc(' ', stdout);
  707.                                 }
  708.                             else {
  709.                                 newlinect = 0;
  710.                                 putc(c, stdout);
  711.                             }
  712.                       }
  713.                      }
  714.                      /* The following line is only needed with line-
  715.                  buffering */
  716.                      putc('\n', stdout);
  717.                      exit(0);
  718.                  }
  719.  
  720.                  lc2strncmp(s1, s2, len)
  721.                  char *s1, *s2;
  722.                  int len;
  723.                  {
  724.                      if (!s1 || !s2) return (-1);
  725.                      while (*s1 && *s2 && len > 0) {
  726.                       if (*s1 != *s2 && (tolower(*s1) != *s2)) return(-
  727.  
  728.  
  729.  
  730. Borenstein                                                     [Page 13]
  731.  
  732. RFC 1523           A text/enriched MIME Content-type      September 1993
  733.  
  734.  
  735.                  1);
  736.                       ++s1; ++s2; --len;
  737.                      }
  738.                      if (len <= 0) return(0);
  739.                      return((*s1 == *s2) ? 0 : -1);
  740.                  }
  741.  
  742.    It should be noted that one can do considerably better than this in
  743.    displaying text/enriched data on a dumb terminal.  In particular, one
  744.    can replace font information such as "bold" with textual emphasis
  745.    (like *this* or _T_H_I_S_).  One can also properly handle the
  746.    text/enriched formatting commands regarding indentation,
  747.    justification, and others.  However, the above program is all that is
  748.    necessary in order to present text/enriched on a dumb terminal
  749.    without showing the user any formatting artifacts.
  750.  
  751. Appendix B -- Differences from RFC 1341 text/richtext
  752.  
  753.    Text/enriched is a clarification, simplification, and refinement of
  754.    the type defined as text/richtext in RFC 1341.  For the benefit of
  755.    those who are already familiar with text/richtext, or for those who
  756.    want to exploit the similarities to be able to display text/richtext
  757.    data with their text/enriched software, the differences between the
  758.    two are summarized here. Note, however, that text/enriched is
  759.    intended to make text/richtext obsolete, so it is not recommended
  760.    that new software generate text/richtext.
  761.  
  762.    0.  The name "richtext" was changed to "enriched", both to
  763.    differentiate the two versions and because "richtext" created
  764.    widespread confusion with Microsoft's Rich Text Format (RTF).
  765.  
  766.    1.  Clarifications.  Many things were ambiguous or unspecified in the
  767.    text/richtext definition, particularly the initial state and the
  768.    semantics of richtext with multibyte character sets.  However, such
  769.    differences are OPERATIONALLY irrelevant, since the clarifications
  770.    offered in this document are at least reasonable interpretations of
  771.    the text/richtext specification.
  772.  
  773.    2.  Newline semantics have changed.  In text/richtext, all CRLFs were
  774.    mapped to spaces, and line breaks were indicated by "<nl>".  This has
  775.    been replaced by the "n-1" rule for CRLFs.
  776.  
  777.    3.  The representation of a literal "<" character was "<lt>" in
  778.    text/richtext, but is "<<" in text/enriched.
  779.  
  780.    4.  The "verbatim" and "nofill" commands did not exist in
  781.    text/richtext.
  782.  
  783.  
  784.  
  785.  
  786. Borenstein                                                     [Page 14]
  787.  
  788. RFC 1523           A text/enriched MIME Content-type      September 1993
  789.  
  790.  
  791.    5.  The "param" command did not exist in text/richtext.
  792.  
  793.    6.  The following commands from text/richtext have been REMOVED from
  794.    text/enriched: <COMMENT>, <OUTDENT>, <OUTDENTRIGHT>, <SAMEPAGE>,
  795.    <SUBSCRIPT>, <SUPERSCRIPT>, <HEADING>, <FOOTING>, <ISO-8859-[1-9]>,
  796.    <US-ASCII>, <PARAGRAPH>, <SIGNATURE>, <NO-OP>, <LT>, <NL>, and <NP>.
  797.  
  798.    7.  All claims of SGML compatibility have been dropped.  However,
  799.    with the possible exceptions of the new semantics for CRLF and "<<"
  800.    can be implemented, text/enriched should be no less SGML-friendly
  801.    than text/richtext was.
  802.  
  803.    8.  In text/richtext, there were three commands (<NL>, <NP>, and
  804.    <LT>) that did not use balanced closing delimiters.  Since all of
  805.    these have been eliminated, there are NO exceptions to the
  806.    nesting/balancing rules in text/enriched.
  807.  
  808.    9.  The limit on the size of formatting tokens has been increased
  809.    from 40 to 60 characters.
  810.  
  811.    References
  812.  
  813.    [RFC-1341] Borenstein, N., and N.  Freed, "MIME (Multipurpose Internet
  814.    Mail Extensions): Mechanisms for Specifying and Describing the Format
  815.    of Internet Message Bodies", RFC 1341, Bellcore, Innosoft, June 1992.
  816.  
  817.    [RFC-1521] Borenstein, N., and N.  Freed, "MIME (Multipurpose Internet
  818.    Mail Extensions) Part One: Mechanisms for Specifying and Describing
  819.    the Format of Internet Message Bodies", RFC 1521, September 1993.
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842. Borenstein                                                     [Page 15]
  843.